package com.nbicc.common.exception;

import com.nbicc.common.ResponseObj;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by li on 17/12/26.
 */
@ApiIgnore()
@Slf4j
@RestController
@RequestMapping(value = "/")
public class MyExceptionHandler {

    @RequestMapping(value = "/myError" )
//    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ResponseBody
    public ResponseObj myError(HttpServletRequest request, HttpServletResponse response) {
        ResponseObj responseObj = (ResponseObj) request.getAttribute("result");
        response.setStatus(responseObj.getStatus());
        log.error(responseObj.toString());
        return responseObj;
    }

}
